<template>
	<view class="content">
		<!--搜索-->
		<view class="status_bar">
		</view>
		<view class="search">
			<u-search :show-action="true" actionText="取消" borderColor="#7A7DEE" bgColor="#FFFFFF" placeholder="輸入關鍵字搜索"
				v-model="keyword" @change="changesearch" @custom="cancel" @search="search"></u-search>
		</view>
		<view class="history">
			<view class="history-top">
				搜索推荐
			</view>
			<view class="history-item" v-for="(item,index) in searchlist" :key="index"
				@click="searchtab(item.goods_name)">
				{{item.goods_name}}
			</view>

		</view>

	</view>
</template>

<script>
	import {
		searchlist
	} from '@/network/api/home.js'
	export default {
		data() {
			return {
				keyword: "",
				searchlist: []
			}
		},
		methods: {
			async changesearch() {
				const res = await searchlist(this.keyword)
				this.searchlist = res.data.list

			},
			search() {
				
				uni.navigateTo({
					url: `/pages/classify/search/result?keyword=${this.keyword}`
				})
			},
			searchtab(goods_name) {
				uni.navigateTo({
					url: `/pages/classify/search/result?keyword=${goods_name}`
				})
			},
			cancel() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {

		.status_bar {
			height: var(--status-bar-height);
			width: 100vw;
		}

		.search {
			margin: 16rpx 32rpx;
		}

		.history {
			.history-top {
				margin: 0 32rpx;
				padding: 32rpx 0;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #999999;
				border-bottom: 1rpx solid #DEDEDE;
			}

			.history-item {
				margin: 0 32rpx;
				padding: 32rpx 0;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				border-bottom: 1rpx solid #DEDEDE;
			}
		}
	}
</style>